import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.Timer;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class NoticeJFrame extends JFrame {
    private String message;

    public NoticeJFrame(String message) {
        this.message = message;
        init_NoticeJFrame();
        startTimer();
    }

    private void init_NoticeJFrame() {
        this.setSize(200, 200);
        this.setTitle("提示");
        this.setAlwaysOnTop(true);
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        JLabel label = new JLabel(message);
        label.setHorizontalAlignment(JLabel.CENTER);
        this.add(label);

        this.setVisible(true);
    }

    private void startTimer() {
        int delay = 1000; // 延迟时间，单位为毫秒
        ActionListener taskPerformer = new ActionListener() {
            public void actionPerformed(ActionEvent evt) {
                closeNoticeJFrame();
            }
        };
        Timer timer = new Timer(delay, taskPerformer);
        timer.setRepeats(false); // 设置为 false，表示计时器只触发一次
        timer.start();
    }

    private void closeNoticeJFrame() {
        this.dispose(); // 关闭提示界面
    }

}
